class complex:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def show(self):
        print(self.x, "+", self.y, "i")
    def __add__(self, other):
        if type(other) == type(self):  # 重载complex+complex，判断类型
            return complex(self.x + other.x, self.y + other.y)  # 加法的返回值
        elif type(other) == type(10):  # 重载complex+int,判断类型
            return complex(self.x + other, self.y + other)


# c1=complex(1,2) #有名c1对象
# c1.show()
# complex(1,2).show() #匿名对象

c1 = complex(1, 2)
c2 = complex(3, 5)
# c3=c1+c2
# c3=c1.__add__(c2)
c3=c1+10
c3.show()
c4=c3+c2
c4.show()
